package com.metaera.app.ui.adapters;

import android.app.Activity;
import android.content.Intent;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.metaera.app.Constants;
import com.metaera.app.R;
import com.metaera.app.data.model.PhoneCodeResponse;

import java.util.List;

import androidx.annotation.NonNull;

public class PhoneNumberPickAdapter extends BaseQuickAdapter<PhoneCodeResponse, BaseViewHolder> {

    public PhoneNumberPickAdapter(List<PhoneCodeResponse> data) {
        super(R.layout.item_country_large_padding, data);

        setOnItemClickListener((adapter, view, position) -> {
            Activity context = (Activity) getContext();
            PhoneCodeResponse item = data.get(position);
            context.setResult(Activity.RESULT_OK, new Intent().putExtra(Constants.EXTRA_AREA_CODE, item.getArea_code()));
            context.finish();
        });

    }


    @Override
    protected void convert(@NonNull BaseViewHolder holder, PhoneCodeResponse item) {
        holder.setText(R.id.tv_name, item.getCountry())
                .setText(R.id.tv_code, "+" + item.getArea_code());
    }

}
